{if condition="$instance['instancestatus'] neq 0"}
<style>
    .flowcontent input {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

    .flowcontent select {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

    .flowcontent textarea {
        pointer-events: none;
        border: 1px solid #DDD;
        background-color: #F5F5F5;
    }

</style>
{/if}
<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
    <input type="hidden" id="taskid" name="taskid" value="{$task->id ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="ids" name="ids" value="{$ids ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="flowcode" name="flowcode" value="{$flowCode ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="table" name="table" value="{$table ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="status" name="status" value="{$model.status ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="hidden" id="project_id" name="project_id" value="{$model.project_id ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <input type="text" id="budget_id" name="budget_id" value="{$model.id ?? ''}" required autocomplete="off"
           class="layui-input" disabled>
    <div class="layui-row">
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">申请人1</label>
                <div class="layui-input-block">
                    <input type="text" value="{$originator.nickname ?? ''}" required placeholder="申请人"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目名称</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.name ?? ''}" id="name" required placeholder="日期范围"
                           autocomplete="off"
                           class="layui-input" isxsj='1'>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">填写日期</label>
                <div class="layui-input-block">
                    <input type="text" value="  {$model.create_time ?? ''}" required placeholder="填写日期"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>

        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目主管</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.executive ?? ''}" required placeholder="项目主管"
                           autocomplete="off"
                           class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">样本量</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.sample_num ?? ''}" id="sample_num" required placeholder="样本量"
                           autocomplete="off"
                           class="layui-input" isxsj='1'>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">执行区域</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.execution_area ?? ''}" id="execution_area" required placeholder="执行区域"
                           autocomplete="off"
                           class="layui-input" isxsj='1'>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">开始时间</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.start_time ?? ''}" id="start_time"  required placeholder="开始时间"
                           autocomplete="off"
                           class="layui-input" isxsj='1'>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">结束时间</label>
                <div class="layui-input-block">
                    <input type="text" value="{$model.pb.end_time ?? ''}"  id="end_time" required placeholder="结束时间"
                           autocomplete="off"
                           class="layui-input" isxsj='1'>
                </div>
            </div>
        </div>
        <div class="layui-col-xs6 layui-col-sm6 layui-col-md4">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目描述</label>
                <div class="layui-input-block">
                    <input class="layui-input" isxsj='1' id="content" value="{$model.content ?? ''}">
                </div>
            </div>
        </div>
        {if $model.status eq '-1'}
        <div class="layui-row" id="project_sample">
            {foreach $model.pb.ProjectBudgetTypeConfig as $key=>$vo}
            <input type="hidden" value="{$vo.id ?? ''}" name="type_id[{$key}]" lay-verify="required"
                   placeholder="请输入项目类型" autocomplete="off"
                   class="layui-input">
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">项目类型</label>
                    <div class="layui-input-block">
                        <input type="text" value="{$vo.type_name ?? ''}" name="type_name[{$key}]" lay-verify="required"
                               placeholder="请输入项目类型" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">主样本量</label>
                    <div class="layui-input-block">
                        <input type="text" value="{$vo.main_sample_num ?? ''}" name="main_sample_num[{$key}]"
                               lay-verify="required" id="main_sample_num" required placeholder="请输入主样本量"
                               autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            <div class="layui-col-xs12 layui-col-sm12 layui-col-md4">
                <div class="layui-form-item">
                    <label class="layui-form-label">放大样本量</label>
                    <div class="layui-input-block">
                        <input type="text" value="{$vo.enlarge_sample_num ?? ''}" name="enlarge_sample_num[{$key}]"
                               lay-verify="required" id="enlarge_sample_num" required
                               placeholder="请输入放大样本量" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
            </div>
            {/foreach}
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目成本</label>
                <div class="layui-input-block">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="text-align: center;">计划成本22</th>
                            <th style="text-align: center;">数量</th>
                            <th style="text-align: center;">单价</th>
                            <th style="text-align: center;">金额(元)</th>
                            <th style="text-align: center;">备注</th>
                        </tr>
                        </thead>
                        <tbody id="index-table">
                        <div style="display: none;"><select lay-search="" id="select">
                            <option value="">直接选择或搜索选择</option>
                            {foreach $plan as $key=>$vo}
                            <option value="{$vo.id}">{$vo.name}</option>
                            {/foreach}
                        </select></div>

                        {foreach $model.pb.ProjectBudgetPlanConfig as $key=>$vo}
                        <tr>
                            <input type="hidden" name="config_id[{$key}]" value="{$vo.id ?? ''}" placeholder="￥"
                                   lay-verify="required" autocomplete="off"
                                   class="layui-input input price">
                            <td>
                                <select name="cost_id[{$key}]" lay-search="" lay-verify="required">
                                    <option value="">直接选择或搜索选择</option>
                                    {foreach $plan as $key=>$vos}
                                    <option value="{$vos.id}" {if condition="$vo.ProjectPlan['id'] eq $vos.id" }selected{/if}>{$vos.name}</option>
                                    {/foreach}
                                </select>
                            </td>
                            <td style="text-align: center;">
                                <input type="number " lay-verify="number" name="num[{$key}]" value="{$vo.num ?? ''}" lay-verify="required"
                                       placeholder="1,2,3,4"
                                       autocomplete="off"
                                       class="layui-input input num">
                            </td>
                            <td style="text-align: center;">
                                <input type="number" name="unit_price[{$key}]" value="{$vo.unit_price ?? ''}" placeholder="￥"
                                       lay-verify="required" autocomplete="off"
                                       class="layui-input input price">
                            </td>
                            <td style="text-align: center;">
                                <input type="number" placeholder="￥" id="final" autocomplete="off" value="{$vo.sum_of_money ?? ''}"
                                       name="sum_of_money[{$key}]"
                                       class="layui-input final" disabled>
                            </td>
                            <td style="text-align: center;"><input type="text" name="remark[{$key}]" value="{$vo.remark ?? ''}"
                                                                   placeholder="请输入备注" autocomplete="off"
                                                                   class="layui-input"></td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        {else /}
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目类型</label>
                <div class="layui-input-block">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="text-align: center;">项目类型</th>
                            <th style="text-align: center;">主样本量</th>
                            <th style="text-align: center;">放大样本量</th>

                        </tr>
                        </thead>
                        <tbody id="index-table">
                        {foreach $model.pb.ProjectBudgetTypeConfig as $key=>$value}
                        <tr>
                            <td>
                                {$value.type_name ?? ''}
                            </td>
                            <td style="text-align: center;">
                                {$value.main_sample_num ?? ''}
                            </td>
                            <td style="text-align: center;">{$value.enlarge_sample_num ?? ''}</td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 layui-col-sm12 layui-col-md12">
            <div class="layui-form-item ">
                <label class="layui-form-label">项目成本</label>
                <div class="layui-input-block">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="text-align: center;">计划成本1</th>
                            <th style="text-align: center;">数量</th>
                            <th style="text-align: center;">单价</th>
                            <th style="text-align: center;">总价</th>
                            <th style="text-align: center;">备注</th>
                        </tr>
                        </thead>
                        <tbody id="index-table">
                        {foreach $model.pb.ProjectBudgetPlanConfig as $key=>$value}
                        <tr>
                            <td>
                                {$value.ProjectPlan.name ?? ''}
                            </td>
                            <td style="text-align: center;">
                                {$value.num ?? ''}
                            </td>
                            <td style="text-align: center;">{$value.unit_price ?? ''}</td>
                            <td style="text-align: center;">{$value.sum_of_money ?? ''}</td>
                            <td style="text-align: center;">{$value.remark ?? ''}</td>
                        </tr>

                        {/foreach}
                        <tr>
                            <td colspan="3"></td>
                            <td colspan="2">合计：{$zongjine ?? 0}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        {/if}
        {if condition="$instance['instancestatus'] neq 2"}
        <div class="layui-form-item">
            <label class="layui-form-label">审批意见</label>
            <div class="layui-input-block">
                <textarea id="comment" class="layui-textarea" data-use-current="true" name="comment"></textarea>
            </div>
        </div>
        {/if}
        <div class="layui-form-item">
            <label class="layui-form-label">审批历史</label>
            <div class="layui-input-block">
                <table class="layui-table">
                    <thead>
                    <tr>
                        <td>审批人</td>
                        <td>审批步骤</td>
                        <td>审批意见</td>
                        <td>审批时间</td>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="history" id="vo" }
                    <tr>
                        <td>{$vo.nickname}</td>
                        <td>{$vo.stepname}</td>
                        <td>{$vo.comment}</td>
                        <td>{$vo.completedtime}</td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </div>
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="layui-input-block">
                {if condition="$mode neq 'view'"}
                {if condition="$instance['instancestatus'] eq 0"}
                <button type="button" id='start' class="layui-btn">提交</button>
                {elseif condition="$instance['instancestatus'] eq 1"/}
                <button type="submit" id='agree' class="layui-btn btn-success btn-embossed disabled"
                        style="background-color: #18bc9c !important; border-radius: 5px;">同意
                </button>
                <button type="submit" id='refuse' class="layui-btn btn-danger btn-embossed disabled"
                        style="background-color: #e74c3c !important; border-radius: 5px;">拒绝
                </button>
                {else/}
                {/if}
                {/if}
                <!--            {if condition="$instance['instancestatus'] neq 2 and $instance['instancestatus'] neq 3 and $instance['originator'] eq $auth->id"}-->
                <!--                 <button type="submit" id='cancel' class="layui-btn btn-danger btn-embossed disabled"style="background-color: #e74c3c !important; border-radius: 5px;">取消</button>-->
                <!--            {/if}-->
                <button type="button" id='flowchart' class="layui-btn layui-btn-warm btn-embossed"
                        style="background-color: #f39c12 !important; border-radius: 5px;">流程图
                </button>
            </div>
        </div>
    </div>
</div>
<script src="/static/admin/layui/layui.js"></script>
<script>
    var url = "{:url('Myworkitem/flowchart')}", edit = "{:url('Myworkitem/edit')}",
        refuse = "{:url('Myworkitem/refuse')}", check = "{:url('Myworkitem/check')}";
    layui.config({
        base: '/static/admin/' //静态资源所在路径
    }).extend({
        index: 'lib/index', //主入口模块
    }).use(['index', 'form','laydate','flow'], function () {
        var $ = layui.$, form = layui.form  , laydate = layui.laydate;
        laydate.render({
            elem: '#start_time'
            , format: "yyyy-MM-dd"
            , trigger: 'click'//呼出事件改成click
        });

        laydate.render({
            elem: '#end_time'
            , format: "yyyy-MM-dd"
            , trigger: 'click'//呼出事件改成click
        });
        var taskid = $('#taskid').val();
        var ids = $('#ids').val();
        var flowcode = $('#flowcode').val();
        var table = $('#table').val();
        var param = $.param({'taskid': taskid, 'ids': ids, 'flowcode': flowcode});
        var status = $('#status').val();
        if (status != -1 || status != "-1") {
            $("[isxsj='1']").attr("disabled", true)
        }
        $('#agree').on('click', function (res) {
            var comment = $('#comment').val();
            $.ajax({
                url: edit,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment,
                    'status':status
                },
                // beforeSend: function () {
                //     layer.load(2, {
                //         shade: [0.6, '#fff'], content: '数据提交中...', success: function (layero) {
                //             layero.find('.layui-layer-content').css({
                //                 'padding-top': '6px',
                //                 'width': '150px',
                //                 'padding-left': '40px'
                //             });
                //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                //                 'width': '150px !important',
                //                 'background-position': '2px 0 !important'
                //             });
                //         }
                //     });
                // },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#refuse').on('click', function (res) {
            var comment = $('#comment').val();
            $.ajax({
                url: refuse,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment
                },
                beforeSend: function () {
                    layer.load(2, {
                        shade: [0.6, '#fff'], content: '数据提交中...', success: function (layero) {
                            layero.find('.layui-layer-content').css({
                                'padding-top': '6px',
                                'width': '150px',
                                'padding-left': '40px'
                            });
                            layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                                'width': '150px !important',
                                'background-position': '2px 0 !important'
                            });
                        }
                    });
                },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#flowchart').on('click', function (res) {
            layer.open({
                type: 2
                , title: "流程图"
                , content: url + '?' + param
                , area: ['70%', '70%']
                , maxmin: true
            });
        });
        $('#cancel').on('click', function (res) {
            console.log("取消");
        });
        $('#start').on('click', function (res) {
            var comment = $('#comment').val();
            var name = $('#name').val();
            var sample_num = $('#sample_num').val();
            var execution_area = $('#execution_area').val();
            var start_time = $('#start_time').val();
            var end_time = $('#end_time').val();
            var content = $('#content').val();
            var project_id = $('#project_id').val();
            var budget_id = $('#budget_id').val();
            //项目类型
            var type_id={}, type_name={}; var main_sample_num={};var enlarge_sample_num = {};
            $("input[name^='type_id']").each(function (i, el) {
                type_id[i] = $(this).val();
            });
            $("input[name^='type_name']").each(function (i, el) {
                type_name[i] = $(this).val();
            });
            $("input[name^='main_sample_num']").each(function (i, el) {
                main_sample_num[i] = $(this).val();
            });
            $("input[name^='enlarge_sample_num']").each(function (i, el) {
                enlarge_sample_num[i] = $(this).val();
            });

            //计划成本
            var cost_id = {},num={},unit_price={},sum_of_money={},remark={},config_id={};
            $("input[name^='config_id']").each(function (i, el) {
                config_id[i] = $(this).val();
            });
            $("select[name^='cost_id']").each(function (i, el) {
                cost_id[i] = $(this).val();
            });
            $("input[name^='num']").each(function (i, el) {
                num[i] = $(this).val();
            });
            $("input[name^='unit_price']").each(function (i, el) {
                unit_price[i] = $(this).val();
            });
            $("input[name^='sum_of_money']").each(function (i, el) {
                sum_of_money[i] = $(this).val();
            });
            $("input[name^='remark']").each(function (i, el) {
                remark[i] = $(this).val();
            });
            $.ajax({
                url: edit,
                type: "post",
                data: {
                    'taskid': taskid,
                    'ids': ids,
                    'flowcode': flowcode,
                    'table': table,
                    'comment': comment,
                    'status':status,
                    'project_id':project_id,
                    'budget_id':budget_id,
                    'name':name,
                    'sample_num':sample_num,
                    'execution_area':execution_area,
                    'start_time':start_time,
                    'end_time':end_time,
                    'content':content,
                    type_id,type_name,main_sample_num,enlarge_sample_num,config_id,cost_id,num,unit_price,sum_of_money,remark
                },
                // beforeSend: function () {
                //     layer.load(2, {
                //         shade: [0.6, '#fff'], content: '数据新增中...', success: function (layero) {
                //             layero.find('.layui-layer-content').css({
                //                 'padding-top': '6px',
                //                 'width': '150px',
                //                 'padding-left': '40px'
                //             });
                //             layero.find('.layui-layer-ico16, .layui-layer-loading .layui-layer-loading2').css({
                //                 'width': '150px !important',
                //                 'background-position': '2px 0 !important'
                //             });
                //         }
                //     });
                // },
                success: function (res) {
                    if (res.code === 200) {
                        layer.msg(res.msg, {icon: 1});
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.closeAll();		//关闭窗口
                        window.parent.location.reload();
                    } else {
                        layer.msg(res.msg, {icon: 5});
                        return false;
                    }
                }
            });
        });
        $('#check').on('click', function (res) {
            layer.open({
                type: 2
                , title: "查看{$schme['flowname']}({$instance['instancecode']})"
                , content: check + '?' + param
                , area: ['80%', '80%']
                , maxmin: true
                // , btn: ['确定', '流程图', '取消']
                // , success: function (res) {
                //     console.log(data.instancestatus);
                // }
            });
        })
    });
</script>
